﻿<!DOCTYPE html>
<html>
<head>
    <title>CGI</title>
</head>
<body>
    <h1>Our Page</h1>
    <script>
        //01
        //check for variable is array or not
        
        var entries = new Array('Trains', 'Plains', 'Automobiles');
        console.log(entries instanceof Array);

        //array is loosly typed (numeric,string,bool all together)
        var entries = new Array('Trains', 42, true);
        console.log(entries instanceof Array);

        //without new keyword
        var entries = Array('Trains', 'Plains', 'Automobiles');
        console.log(entries instanceof Array);

        //without array keyword by using brackets
        var entries = ['Trains', 'Plains', 'Automobiles'];
        console.log(entries instanceof Array);
        

        //02
        //accessing array elements, array are zero based
        /*
        var entries = ['Trains', 'Plains', 'Automobiles'];
        console.log(entries[0]);
        console.log(entries[2]);
        console.log(entries[3]);
        */

        //03
        //array initialization
        /*
        var entries = new Array(5);
        console.log(entries.length);

        var entries = new Array("5");
        console.log(entries.length);

        var entries = [];
        console.log(entries.length);

        //one defined value for each comma
        //4 for IE 8 or lower
        var entries = [, , ,];
        console.log(entries.length);
        */

        //04
        //other 8 elements are undefined
        /*
        var entries = ['Planes', 'Trains'];
        entries.length = 10;
        console.log(entries.length);
        //'Trains' is wipe out
        var entries = ['Planes', 'Trains'];
        entries.length = 1;
        console.log(entries[0]);
        console.log(entries[1]);
        */

        //05
        //array entries are overwritten
        /*
        var entries = ['Planes', 'Trains', 'Automobiles'];
        entries[2] = 'Cars';
        console.log(entries[0]);
        console.log(entries[1]);
        console.log(entries[2]);

        //array strech from 0 to 42
        var entries = ['Planes', 'Trains', 'Automobiles'];
        entries[42] = 'Cars';
        console.log(entries[42]);
        console.log(entries.length);
        */

        //06
        //append element in last of array (one way)
        /*
        var entries = ['Planes', 'Trains', 'Automobiles'];
        entries[entries.length] = 'Bicycles';
        console.log(entries.length);
        */

        //07
        //comma separated string from array
        /*
        var entries = ['Planes', 'Trains', 'Automobiles'];
        console.log(entries.toString());

        //valueOf only for numeric elements array
        var ratings = [5, 2, 4];
        console.log(ratings.valueOf());
        */

        //08
        //join of array elements 
        /*
        var ratings = [5, 2, 4];
        console.log(ratings.join(','));
        console.log(ratings.join('|'));
        */
    </script>
</body>
</html>